package com.zuoshenge.main.excel.export;

import com.zuoshenge.main.entity.Course;
import com.zuoshenge.main.service.CourseService;
import com.zuoshenge.tool.excel.BaseEasyExcelExport;
import com.zuoshenge.util.CaffeineCacheUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.*;

/**
 * 商品数据导出
 *
 * @author: ChickenWing
 * @date: 2023/3/5
 */
@Component
public class CourseExcelExport extends BaseEasyExcelExport<Course> {

    @Resource
    private CourseService courseService;
    @Resource
    private CaffeineCacheUtil caffeineCacheUtil;

    /**
     * 数据导出
     */
    public void exportWithBigData(String fileName, Map<String, Object> conditions, Boolean isEmptyExcel) {
        this.exportExcel(fileName, conditions, isEmptyExcel);
    }

    @Override
    protected List<List<String>> getExcelHead() {
        List<List<String>> head = new ArrayList<>();
        head.add(Collections.singletonList("课程名"));
        head.add(Collections.singletonList("课程号"));
        head.add(Collections.singletonList("任课教师"));
        head.add(Collections.singletonList("教室"));
        head.add(Collections.singletonList("课程名额"));
        head.add(Collections.singletonList("课程类型"));
        // head.add(Collections.singletonList("是否结课"));
        return head;
    }

    @Override
    protected Long dataTotalCount(Map<String, Object> conditions) {
        return courseService.queryCount(conditions);
    }

    @Override
    protected Long eachSheetTotalCount() {
        return 5000L;
    }

    @Override
    protected Long eachTimesWriteSheetTotalCount() {
        return 2000L;
    }

    @Override
    protected void buildDataList(List<List<String>> resultList, Map<String, Object> condition,
                                 Long pageNo, Long pageSize) {
        List<Course> courseList = courseService.queryByPage(new Course(), pageNo, pageSize);
        if (CollectionUtils.isNotEmpty(courseList)) {
            courseList.forEach(course -> {
                resultList.add(Arrays.asList(course.getCourseName(),course.getCid(), course.getTeacher(), course.getRoom(),course.getQuota().toString(), course.getType()));
            });
        }
    }
}